package com.hsytech.dijiebao.person.activity;

import org.json.JSONObject;

import com.hsytech.dijiebao.R;
import com.hsytech.dijiebao.base.BaseActivity;
import com.hsytech.dijiebao.utils.SharedPreferencesTools;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ChangePasswordActivity extends BaseActivity {
	private ImageButton top_back_btn;
	private Button bar_right_top_btn;
	private TextView bar_title_tv;
	private EditText old_password, new_password, confir_new_password;
	private LinearLayout finish;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.change_password);
		initTitle();
		initBody();
	}

	private boolean checkBeforePost() {

		if (new_password.getText().toString().equals("")) {
			showToast("����д����");
			return false;
		} else if (old_password.getText().toString().equals("")) {
			showToast("����ԭ����");
			return false;
		} else if (confir_new_password.getText().toString().equals("")) {
			showToast("��ȷ������");
			return false;
		} else if (!confir_new_password.getText().toString().trim().equals(new_password.getText().toString().trim())) {
			showToast("�������벻һ��");
			return false;
		}
		return true;
	}

	private void initBody() {
		old_password = (EditText) findViewById(R.id.old_password);
		new_password = (EditText) findViewById(R.id.new_password);
		confir_new_password = (EditText) findViewById(R.id.confir_new_password);
		finish = (LinearLayout) findViewById(R.id.finish);
		finish.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (checkBeforePost()) {

					postHttp();
				}
			}
		});
	}

	private void initTitle() {
		top_back_btn = (ImageButton) findViewById(R.id.top_back_btn);
		top_back_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();

			}
		});
		bar_right_top_btn = (Button) findViewById(R.id.bar_right_top_btn);
		bar_right_top_btn.setVisibility(View.GONE);
		bar_title_tv = (TextView) findViewById(R.id.bar_title_tv);
		bar_title_tv.setText("�޸�����");

	}

	private void postHttp() {
		// ����
//		RequestParams data = new RequestParams();
//		data.put("password", old_password.getText().toString().trim());
//		data.put("new_password", new_password.getText().toString().trim());
//		data.put("token", SharedPreferencesTools.getTOKEN(this));
//		HttpUtils.post("http://djb.dev.hsydev.com/api.php/User/updatePassword", ChangePasswordActivity.this, data,
//				new JsonResponseHandler() {
//					@Override
//					public void onSuccess(JSONObject data) {
//						showToast("�޸ĳɹ�");
//						finish();
//					}
//
//					@Override
//					public void onError(String mess) {
//						super.onError(mess);
//						showToast(mess);
//					}
//				});
	}
}
